You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

19 lines
686 B

import { getCache, setCache } from "#server/utils/context";
import { getCardById } from "../../service/card";
export default defineWrappedResponseHandler(async (event) => {
const idParam = getRouterParam(event, "id");
if (!idParam) return R.throwError(400, "缺少卡片 ID", null);
const id = parseInt(idParam);
if (isNaN(id)) return R.throwError(400, "卡片 ID 格式不正确", null);
const cacheKey = `card:${id}`;
const cached = await getCache(cacheKey);
if (cached) return R.success(cached);
const card = await getCardById(id);
if (!card) return R.throwError(404, "Card not found", null);
await setCache(cacheKey, card, 60);
return R.success(card);
});